// var isPalindrome = function (head) {
//     let arr = []
//     let pre = head
//     while (pre !== null) {
//         arr.push(pre.val)
//         pre = pre.next
//     }
//     let len = arr.length
//     let left = 0, right = len - 1
//     while (left < right) {
//         if (arr[left] !== arr[right]) return false
//         left++
//         right--
//     }
//     return true
// };

var isPalindrome = function (head) {
    let arr = [];
    let cur = head;
    while (cur !== null) {
        arr.push(cur.val);
        cur = cur.next;
    }

    let len = arr.length;
    let left = 0, right = len - 1;
    while (left < right) {
        if (arr[left] !== arr[right]) {
            return false;
        } else {
            left++;
            right--;
        }
    }
    return true;
}